package main

func MakeAll(cfg *config.Config) {
	// repo 是git仓库的信息
	// lim是为了控制并发的
	// resultCh 是为了收集仓库的报错信息
	for repo := range cfg.Repos {
		go newSearcherConcurrent(repo, lim, resultCh)
	}
	// xx
}

func newSearcherConcurrent() {
	// acquire a token from the rate limiter
	lim.Acquire()
	defer lim.Release()

	s, err := newSearcher(repo)
	if err != nil {
		resultCh <- searcherResult{
			name: name,
			err:  err,
		}
		return
	}

	resultCh <- searcherResult{
		name:     name,
		searcher: s,
	}
}

func newSearcher(
	dbpath, name string,
	repo *config.Repo) (*Searcher, error) {

	// 这里是做克隆
	err := wd.PullOrClone(vcsDir, repo.Url)
	if err != nil {
		return nil, err
	}

	go func() {
		<-s.updateCh

		s.CompleteShutdown()
	}()

	return s, nil
}
func main() {

}
